﻿using System;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Text;
using Texfina.Core.Common;
using Texfina.Common.Mg;
using Texfina.Common.Rh;
using Texfina.Core.Web;
using Texfina.Core.Data;
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using Texfina.Entity.Sy;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;
using RHBOMnt = Texfina.BOMnt.Rh;
using SYBOQry = Texfina.BOQry.Sy;
using System.IO;

namespace RH
{
    public partial class wfProcPlaCtaCteMnt : EditPage
   {
      public const int _GRDLIST_STANULADO = 9;
      protected void Page_Load(object sender, EventArgs e)
      {
         if (this.IsPostBack)
         {
            this.LoadInPostBack();
            return;
         }
         this.LoadData();
      }
      public override void LoadInPostBack()
      {
         this.RegisterGeneralScripts();
      }
      public override void LoadInitialSettings()
      {
         this.FormEditAction = (FormEditAction)Enum.Parse(typeof(FormEditAction), Request.QueryString["formEA"]);
         this.SetInitialTitle("Descuentos Cta.Cte.");
      }
      public override void DataToControls()
      {

         EProcPlani objEA = new EProcPlani();
         IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.ProcPlani));
         objEA.IdPeriodo = Session[ConstSessionVar.PERIODO].ToString();
         objEA.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         objEA.IdMes = Request.QueryString["IdMes"];
         objEA.IdForPago = Request.QueryString["idForPago"];
         objEA.IdPlanilla = Request.QueryString["IdPlanilla"];

         if (Request.QueryString["NuProcAnual"] != null)

            objEA.NuProcAnual = Convert.ToInt16(Request.QueryString["NuProcAnual"]);

         this.txtNroProcAnual.Text = Request.QueryString["NuProcAnual"];
         objEA = (EProcPlani)objBO.GetByKey(objEA);

         if (objEA != null)
         {
            WebHelper.EntityToControl(objEA, "IdPlanilla", txtidPlanilla);

            EPlanilla objEPla = new EPlanilla();
            IBOQuery objBOPla = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.Planilla));
            objEPla.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
            objEPla.IdPlanilla = Request.QueryString["IdPlanilla"];
            objEPla = (EPlanilla)objBOPla.GetByKey(objEPla);
            if (objEPla != null)
               WebHelper.EntityToControl(objEPla, "DsPlanilla", txtdsPlanilla);

         }

         MGBOQry.ITablaGen objBOI = (MGBOQry.ITablaGen)WCFHelper.GetObject<MGBOQry.ITablaGen>(typeof(MGBOQry.TablaGen));
         ETablaGenDet objEDet = new ETablaGenDet();
         objEDet.IdTabla = ConstMultitabla.FORMA_PAGO;
         objEDet.IdCodigo = Request.QueryString["idForPago"];
         objEDet = (ETablaGenDet)objBOI.GetDetailByKey(objEDet);

         if (objEDet != null)
            WebHelper.EntityToControl(objEDet, "DsDescrip", txtdsFormaPago);



         EProcPlaCtaCte objEB = new EProcPlaCtaCte();

         RHBOQry.IPrestamo objBOC = (RHBOQry.IPrestamo)WCFHelper.GetObject<RHBOQry.IPrestamo>(typeof(RHBOQry.Prestamo));

         objEB.IdPeriodo = Session[ConstSessionVar.PERIODO].ToString();
         objEB.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         objEB.IdForPago = Request.QueryString["IdForPago"];
         objEB.IdPlanilla = Request.QueryString["IdPlanilla"];
         objEB.NuProcAnual = int.Parse(Request.QueryString["NuProcAnual"].ToString());

         DataTable dt = objBOC.GetPrestaCuotaxProcPlanilla(objEB);

         this.GridSetDataBinding(grdList, dt);

         }
  
      
      protected void grdList_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
         //if (e.Row.RowType == DataControlRowType.DataRow)
         //{
         //   if (e.Row.Cells[_GRDLIST_STANULADO].Text == ConstFlagEstado.ACTIVADO)
         //   { e.Row.ForeColor = System.Drawing.Color.Red; }
         //}


      }
  
     
      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
         if (e.Item == null)
            return;

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_SAVE:
            case ConstMenuToolbarValue.BUTTON_SAVENEW:
            case ConstMenuToolbarValue.BUTTON_EXIT:
               this.Response.Redirect("wfProcPlaRegBnd.aspx");
               break;
         }

      }
      public override void RegisterGeneralScripts()
      {
         txtidPlanilla.Attributes.Add("readonly", "true");
         txtdsFormaPago.Attributes.Add("readonly", "true");
         txtdsPlanilla.Attributes.Add("readonly", "true");
         txtNroProcAnual.Attributes.Add("readonly", "true");

         StringBuilder sb = new StringBuilder();

         sb.AppendLine("function validateEditForm(key){");

         //sb.AppendLine("var varRpta = isEmptyControl('" + this.txtdsPlanilla.ClientID + "','Ingrese Descripcion Planilla');");
         //sb.AppendLine("if(varRpta==true)");
         //sb.AppendLine("return !varRpta;");
         //sb.AppendLine("var varRpta = isEmptyControl('" + this.txtnuProcAnual.ClientID + "','Ingrese Numero de Proceso Anual');");
         //sb.AppendLine("if(varRpta==true)");
         //sb.AppendLine("return !varRpta;");

         sb.AppendLine("menu_doPostBack('" + mnuToolbar.ClientID + "','" + mnuToolbar.UniqueID + "',key);");
         sb.AppendLine("}");

         ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptRegister", sb.ToString(), true);
      }
      }
}